import axios from 'axios'

//create axios instance
const service = axios.create({
    baseURL: serverApiHost.url,
    timeout: 60000,
    withCredentials: true,  //携带cookie
    headers: {
        'Content-Type': 'application/json',
        'token': 'token-value'
    }
})

//添加请求拦截器
service.interceptors.request.use(
    function (config) {
        //发送请求之前做些什么
        return config;
    },
    function (error) {
        //对请求错误做一些处理
        console.log(error)
        return Promise.reject(error)
    }
)

//添加响应拦截器
service.interceptors.response.use(
    function (response) {
        console.log(response);
        return response.data
    },
    function (error) {
        console.log(error)
        return Promise.reject(error)
    }
)

export default service